<?php

namespace StudyBuddy;

/**
 * Static class to handle
 * creation of record in REFERRER, Profile,
 * Location, Album
 *
 * These are all performed during the user registration,
 * right after the new record is created in USERS table
 *
 * This class is static so methods can easily be called
 * from the normal registration
 * as well as from external auth registration classes
 *
 */
class PostRegistration {

    /**
     * If user has cookie 'ref' then we create record
     * in USER_REFERRER and it will contain the url
     * from which use initially came from on his first visit
     * (before he was even registered)
     *
     * @return void
     */
    public static function createReferrerRecord(Registry $oRegistry, User $oUser) {
        $ref = (!empty($_COOKIE['ref'])) ? filter_input(INPUT_COOKIE, 'ref', FILTER_SANITIZE_URL) : '';
        if (!empty($ref)) {
            $a = array('users_id' => $oUser->getUid(), 'referer_url' => $ref);
            $oRegistry->Mongo->USER_REFEREF->insert($a);
        }
    }

}
